package com.jiaai.cloud.wx.controller;

import com.jiaai.cloud.base.entity.RestResultGenerator;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.wx.entity.TGuestbook;
import com.jiaai.cloud.wx.service.ITGuestbookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 留言板信息表 前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-09-22
 */
@Controller
@RequestMapping("/api/v1/tguestbook")
public class TGuestbookController {
	@Autowired
    private ITGuestbookService itGuestbookService;

    /**
     * 添加一个留言信息
     * @param userid
     * @param tGuestbook
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value = "/aguestbook",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"} )
    @ResponseBody
    public Object addAGuestbook(@RequestHeader Integer userid, @RequestBody TGuestbook tGuestbook) throws ServiceException {
        tGuestbook.setUserid(userid);
        try {
            itGuestbookService.insert(tGuestbook);
            return RestResultGenerator.genSuccessResult("添加成功");
        } catch (Exception e){
            throw new ServiceException("添加失败", e.getMessage());
        }
    }
}
